<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>班组长选择排产单</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		 .left-label {
		 	width: 120px !important
		 }
		 .layui-table th {
		    text-align: center;
		  }
	</style>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
    	<input class="layui-input" name="searchTime" id="searchTime" placeholder="请选择时间" style="display: inline; width: 80%">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
</div>

<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
<table class="layui-hide" id="table2" lay-filter="table2"></table>


<script type="text/html" id="rowToolbar2">
	<a class="layui-btn layui-btn-xs" lay-event="choose">选择</a>
</script>
 
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
 
<script type="text/javascript">

document.onkeydown = function(e){    
	var ev =document.all ? window.event : e;  
	if(ev.keyCode==13) { 
	    $('.layui-btn').trigger("click");
	return false
	}  
} 
layui.use(['table','layer','upload','form','laydate'], function(){
		var table = layui.table;
		var layer = layui.layer;
		var laydate = layui.laydate;
	    var form = layui.form;
	    
		var $ = layui.jquery, active = {
			reload:function () {
				var searchTime = $("#searchTime").val();
				console.log(searchTime)
				table.reload('contenttable2',{
					method:'get',
					where:{"remark1":searchTime}
				});
			}
		}
		$('.layui-btn').on('click', function(){
	        var type = $(this).data('type');
	        active[type] ? active[type].call(this) : '';
	    });
		table.render({
		    elem: '#tableList'
		    ,url:'${pageContext.request.contextPath }/shedu/selectList.do'
		    ,toolbar: '#toolbar'
		    ,title: '排产单'
		    ,id :'contenttable'
		    ,limits:[10,20,30]
		    ,cols: [[
				      /* {type: 'checkbox', fixed: 'left'}, */
				      {field:'', title:'序号', sort: true, type:'numbers', width: 60},
				      {field:'id', title:'ID'},
				      {field:'starttime', title:'开始时间'},
				      {field:'endtime', title:'结束时间'},
				      {field:'havetime', title:'已有日期'},
				      {field:'remark', title:'审批人'},
				      {field:'remark2', title:'审批时间'},
				      {field:'remark4', title:'审批意见'},
				      {field:'remark3', title:'审批状态'},
				      /*{fixed:'right', title:'操作', toolbar: '#rowToolbar', width:100}*/ 
				    ]],
		    page: true,
		    done: function () {
		        $("[data-field='id']").css('display','none');
		    }
		});
		
		table.render({
		    elem: '#table2'
		    ,url:'${pageContext.request.contextPath }/shedu/selecDetailtList.do'
		    ,title: '排产单明细'
		    ,id :'contenttable2'
		    ,limits:[10,20,30]
		    ,cols: [[
				      
		    		  {field:'id', title:'ID'},
				      {field:'remark1', title:'日期',rowspan: 2,align:'center',width:160},
				      {field:'', title:'当日工作量统计值',colspan: 10, align:'center'},
				      {field:'', title:'0960T',colspan: 10, align:'center'},
				      {field:'', title:'0980T',colspan: 10, align:'center'},
				      {field:'', title:'1080C',colspan: 10, align:'center'},
				      {field:'', title:'1060B',colspan: 10, align:'center'},
				      {fixed:'right', title:'操作', rowspan: 2, toolbar: '#rowToolbar2', width:100},
				    ],
				    [ 
				      {field:'a1', title:'膜丝烘干',width:100},
				      {field:'a2', title:'膜丝缓存',width:100},
				      {field:'a3', title:'膜芯制作',width:100},
				      {field:'a4', title:'组件组装',width:100},
				      {field:'a5', title:'膜丝切割',width:100},
				      {field:'a6', title:'浇铸端盖安装',width:120},
				      {field:'a7', title:'组件吊装离心',width:120},
				      {field:'a8', title:'浇铸端盖拆卸',width:120},
				      {field:'a9', title:'组件欲固化缓存',width:130},
				      {field:'a10', title:'组件切割',width:100},
				      
				      {field:'b1', title:'膜丝烘干',width:100},
				      {field:'b2', title:'膜丝缓存',width:100},
				      {field:'b3', title:'膜芯制作',width:100},
				      {field:'b4', title:'组件组装',width:100},
				      {field:'b5', title:'膜丝切割',width:100},
				      {field:'b6', title:'浇铸端盖安装',width:120},
				      {field:'b7', title:'组件吊装离心',width:120},
				      {field:'b8', title:'浇铸端盖拆卸',width:120},
				      {field:'b9', title:'组件欲固化缓存',width:130},
				      {field:'b10', title:'组件切割',width:100},
				      
				      {field:'c1', title:'膜丝烘干',width:100},
				      {field:'c2', title:'膜丝缓存',width:100},
				      {field:'c3', title:'膜芯制作',width:100},
				      {field:'c4', title:'组件组装',width:100},
				      {field:'c5', title:'膜丝切割',width:100},
				      {field:'c6', title:'浇铸端盖安装',width:120},
				      {field:'c7', title:'组件吊装离心',width:120},
				      {field:'c8', title:'浇铸端盖拆卸',width:120},
				      {field:'c9', title:'组件欲固化缓存',width:130},
				      {field:'c10', title:'组件切割',width:100},
				      
				      {field:'d1', title:'膜丝烘干',width:100},
				      {field:'d2', title:'膜丝缓存',width:100},
				      {field:'d3', title:'膜芯制作',width:100},
				      {field:'d4', title:'组件组装',width:100},
				      {field:'d5', title:'膜丝切割',width:100},
				      {field:'d6', title:'浇铸端盖安装',width:120},
				      {field:'d7', title:'组件吊装离心',width:120},
				      {field:'d8', title:'浇铸端盖拆卸',width:120},
				      {field:'d9', title:'组件欲固化缓存',width:130},
				      {field:'d10', title:'组件切割',width:100},
				      
				      {field:'e1', title:'膜丝烘干',width:100},
				      {field:'e2', title:'膜丝缓存',width:100},
				      {field:'e3', title:'膜芯制作',width:100},
				      {field:'e4', title:'组件组装',width:100},
				      {field:'e5', title:'膜丝切割',width:100},
				      {field:'e6', title:'浇铸端盖安装',width:120},
				      {field:'e7', title:'组件吊装离心',width:120},
				      {field:'e8', title:'浇铸端盖拆卸',width:120},
				      {field:'e9', title:'组件欲固化缓存',width:130},
				      {field:'e10', title:'组件切割',width:100},
				    ]],
		    page: true,
		    done: function () {
		        $("[data-field='id']").css('display','none');
		    }
		});
		
		
		 //监听行单击事件（单击事件为：rowDouble）
		  table.on('row(tableList)', function(obj){
		    var data = obj.data;
			table.reload('contenttable2',{
				method:'get',
				where:{"remark2":data.id}
			});
		  });
		
		/**
	     * 监听行工具事件(选择排产单)
	     */
	     var flag = 0; 
	 	 table.on('tool(table2)', function(obj){
	 		 if(obj.event === 'choose'){
	 			if(flag == 0){
	 				var id = obj.data.id;
		 		 	$.ajax({
		 		 		url : '${pageContext.request.contextPath }/teamRecordMana/getTeamRecordByTime.do',
			 			data : {"productionId":id},
			 			type : "post",
			 			dataType : "json",
		 		 	}).done(
	 					function(res) {
	 						if (res == 0) {
	 							layer.confirm('是否已选过班次？', function(index){
	 								layer.confirm('确定选择吗？', function(index){
		 			 		 		 	if(flag == 0){
			 			 		 		 	$.ajax({
			 			 		 				url : '${pageContext.request.contextPath }/teamRecordMana/saveTeamRecord.do',
			 			 		 				data : {"productionId":id},
			 			 		 				type : "post",
			 			 		 				dataType : "json",
			 			 		 				}).done(
			 			 		 					function(res) {
			 			 		 						if (res > 0) {
			 			 		 							flag = 1;
			 			 		 							toastr.success('选择成功！');
			 			 		 							setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
			 			 		 								//关闭模态框
			 			 		 								// 父页面刷新
			 			 		 								window.location.reload(); 
			 			 		 							},2000);
			 			 		 						}else{
			 			 		 							flag = 1;
			 			 		 							toastr.error('选择失败！');
			 			 		 						}
			 			 		 					}
			 			 		 				).fail(
			 			 		 					function(res) {
			 			 		 						flag = 1;
			 			 		 						toastr.error('选择失败！');
			 			 		 					}
			 			 		 				)
		 			 		 		 	}
	 			 		 				return false;
	 			 		 		 	});
	 							});
	 						}else if(res == 1){
	 							layer.confirm('已经选过排产单，是否更改选择？', function(index){
	 			 		 		 	if(flag == 0){
		 			 		 		 	$.ajax({
		 			 		 				url : '${pageContext.request.contextPath }/teamRecordMana/updateTeamRecordOnPositionId.do',
		 			 		 				data : {"productionId":id},
		 			 		 				type : "post",
		 			 		 				dataType : "json",
		 			 		 				}).done(
		 			 		 					function(res) {
		 			 		 						if (res > 0) {
		 			 		 							flag = 1;
		 			 		 							toastr.success('修改成功！');
		 			 		 							setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
		 			 		 								//关闭模态框
		 			 		 								// 父页面刷新
		 			 		 								window.location.reload(); 
		 			 		 							},2000);
		 			 		 						}else{
		 			 		 							flag = 1;
		 			 		 							toastr.error('修改失败！');
		 			 		 						}
		 			 		 					}
		 			 		 				).fail(
		 			 		 					function(res) {
		 			 		 						flag = 1;
		 			 		 						toastr.error('修改失败！');
		 			 		 					}
		 			 		 				)
	 			 		 		 		}
	 			 		 				return false;
	 			 		 		 	});
		 						}else if(res == 2){
		 							flag = 0;
		 							toastr.warning("请用班组长工号登录选择排产单！");
		 						}else if(res == 3){
		 							flag = 0;
		 							toastr.warning("请选择与其他班组相同的排产单！");
		 						}
		 					}
		 				).fail(
		 					function(res) {
		 						flag = 1;
		 						toastr.error('选择失败！');
		 					}
		 				)
	 			}
	 		 }
	 	});
    
  //时间格式化
    laydate.render({
      elem: '#searchTime',
      format: 'yyyy-MM-dd'
    });
    laydate.render({
      elem: '#datatime',
      format: 'yyyy-MM-dd'
    });
    laydate.render({
      elem: '#datatime2',
      format: 'yyyy-MM-dd'
    });
});

toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上

//定时更新报表
//重复调用
/* setInterval("taskJob()", 10000);*/
//只调用一次
setTimeout("taskJob()", 5000)
function taskJob(){
	//更新人员报表
	$.ajax({
		type:'post',
		url:'${pageContext.request.contextPath }/reportMana2/renewalUserReport.do',
		success:function(data){
			
		}
	});
	//更新综合日报表
	$.ajax({
		type:'post',
		url:'${pageContext.request.contextPath }/reportMana2/job2.do',
		success:function(data){
			
		}
	});
	//更新设备产量报表
	$.ajax({
		type:'post',
		url:'${pageContext.request.contextPath }/report/gengxinbaobiaoD.do',
		success:function(data){
			
		}
	});
	//更新物料明细报表
	$.ajax({
		type:'post',
		url:'${pageContext.request.contextPath }/report/gengxinbaobiaoM.do',
		success:function(data){
			
		}
	});
	//删除系统日志
	$.ajax({
		type:'post',
		url:'${pageContext.request.contextPath }/logMana/deleteByMonth.do',
		success:function(data){
			
		}
	});
} 

</script>

</body>
</html>